

local ConfigLoader = require("config.loader")
local Settings = require("config.settings")
local config = ConfigLoader.load(Settings.CURRENT_GAME)
local logger = require "utils.logger"
local stateManager = require "utils.state_manager"
local inventory = require "modules.inventory"
local shop = require "modules.shop"
local movement = require "modules.movement"
local combat = require "modules.combat"
local tslib = require "TSLib"


local function main()
    logger.info("运行进入皇榜回收脚本")
    while true do
        local success, err = pcall(function()
            if multiColor({{748, 12, 0x98e5e8},{750, 16, 0x32d5db},{752, 20, 0x08b1b8},{757, 20, 0x59d9de}}) then
                tap(748, 12)
            end
            -- 是否打开客服，关闭客服
            if multiColor({{809, 27, 0xffe11f},{809, 39, 0xffe11f},{809, 44, 0xffe11f},{807, 54, 0xfee01f}}) then
                tap(44, 42)
            end
            mSleep(1000)
            -- 完成皇榜回收，点击两个按钮
            local buttons = {{216, 120, 0x343d41},{681, 599, 0x655945},{1031,518,0x000000},{1239, 179, 0xad702d}}
            movement.clickSeries(buttons)
            -- -- 回收流程
            -- local recycleButtons = {{1551, 321, 0xb37a4f},{792, 625, 0x0b376f},{734, 691, 0x000000},{1044, 158, 0xa50b0b},{914, 144, 0xdda845}}
            -- movement.clickSeries(recycleButtons)
        end)
        if not success then
            logger.error("皇榜回收任务执行出错: " .. tostring(err))
            logger.error("错误堆栈: " .. debug.traceback())
        end
        combat.startAutoAttack()
        -- 使用配置的检测间隔
        local checkInterval = math.random(300, 400)
        logger.info("等待" .. checkInterval .. "秒后进行下一次检测")
        mSleep(checkInterval * 1000)
    end
end

return {
    run = main
}